//
//  MezeroCell.m
//  zctx
//
//  Created by apple on 16/1/8.
//  Copyright © 2016年 sanliang. All rights reserved.
//

#import "MezeroCell.h"

@implementation MezeroCell


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addbgImgView];
        [self addIconImgView];
        [self addrightImgView];
        [self addNameLable];
    }
    return self;
}
- (void)awakeFromNib {
    // Initialization code
}

+ (instancetype)MezeroCellWithTableView:(UITableView *)tableView{
    static NSString *cellIndentifier = @"mezero";
    MezeroCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        cell = [(MezeroCell *)[MezeroCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
    }
    if (UserModel.password.length>1) {
        cell.nameLable.text = UserModel.username;
        
        NSLog(@"avater = %@",UserModel.avatar);
        if (UserModel.avatar) {
            [cell.iconImgView sd_setImageWithURL:[NSURL URLWithString:UserModel.avatar] placeholderImage:[UIImage imageNamed:@"projectdetail_icon"]];
        }else{
            cell.iconImgView.image = [UIImage imageNamed:@"projectdetail_icon"];
        }
    }else{
        cell.nameLable.text = @"请登录";
        cell.iconImgView.image = [UIImage imageNamed:@"projectdetail_icon"];
    }
    return cell;
}





-(void)addrightImgView{
    [self.contentView addSubview:self.rightImgView];
    [self.rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.centerY);
        make.height.mas_equalTo(13);
        make.right.equalTo(self.contentView.right).with.offset(-15);
        make.width.mas_equalTo(7);
    }];
}

-(void)addbgImgView{
    [self.contentView addSubview:self.bgImgView];
    [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).with.offset(0);
        make.right.equalTo(self.contentView.right).with.offset(0);
        make.top.equalTo(self.contentView.top).with.offset(0);
        make.bottom.equalTo(self.contentView.bottom).with.offset(0);

    }];
}

-(void)addIconImgView{
    [self.contentView addSubview:self.iconImgView];
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.centerY);
        make.height.mas_equalTo(60);
        make.left.equalTo(self.contentView.left).with.offset(19);
        make.width.mas_equalTo(60);
    }];
    self.iconImgView.layer.masksToBounds = YES;
    self.iconImgView.layer.cornerRadius = 30;
}

-(void)addNameLable{
    [self.contentView addSubview:self.nameLable];
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.centerY);
        make.height.mas_equalTo(21);
        make.left.equalTo(self.iconImgView.right).with.offset(5);
        make.right.equalTo(self.rightImgView.left).with.offset(-20);
    }];
}

-(UIImageView *)rightImgView{
    
    if (!_rightImgView) {
        _rightImgView = [[UIImageView alloc]init];
        _rightImgView.image = [UIImage imageNamed:@"me_right_bai"];
    }
    return _rightImgView;
}

-(UIImageView *)bgImgView{
    
    if (!_bgImgView) {
        _bgImgView = [[UIImageView alloc]init];
        _bgImgView.image = [UIImage imageNamed:@"me_bg"];
    }
    return _bgImgView;
}

-(UIImageView *)iconImgView{
    
    if (!_iconImgView) {
        _iconImgView = [[UIImageView alloc]init];
    }
    return _iconImgView;
}

-(UILabel *)nameLable {
    if (!_nameLable) {
        _nameLable = [[UILabel alloc]init];
        _nameLable.textColor = [UIColor whiteColor];
    }
    return _nameLable;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
